<?php 
namespace Home\Model;
use Think\Model;
class SleepingModel extends Model 
{
    public function getMySleeping($openid)
    {
        $where = array(
            'openid'=>$openid
        );
        return $this->where($where)->find();
    }

    public function getIdSleeping($id)
    {
        $where = array(
            'id'=>$id
        );
        return $this->where($where)->find();
    }

    public function addSleeping($sleepingType, $openid)
    {
        $add = array(
            'sleeping_type' => $sleepingType,
            'openid'        => $openid,
            'create_time'   => time(),
        );
        return $this->add($add);
    }

    public function addPrize($prizeId, $sleepingId)
    {
        $where = array(
            'id' => $sleepingId,
        );
        $add = array(
            'prize_id'   => $prizeId,
            'prize_time' => time(),
        );
        return $this->where($where)->save($add);
    }

    public function guessPlus($sleepingId, $right)
    {
        $where = array(
            'id' => $sleepingId,
        );
        $this->where($where)->setInc('guessnum');
        if(!$right)return true;
        $this->where($where)->setInc('rightnum');
        return true;
    }
}
